<template>
  <div class="goods-list">
    <div class="goods-item" v-for="p in productList" :key="p.p_id">
      <router-link :to="'/home/productlist/productinfo/'+p.p_id">
        <img :src="productImg+p.p_picture" alt="无法加载了-_-"/>
        <h1 class="title">{{p.p_name}}</h1>
        <div class="info">
            <p class="price">
                <span class="now">￥<span class="ys">{{p.p_importPrice}}</span>万元</span>
                <span class="old">￥{{p.p_sellPrice}}万元</span>
            </p>
            <p class="sell">
                <span class="ys">热卖中</span>
                <span>已售：{{p.p_sellNumber}}辆</span>
                <span>剩{{p.p_number}}辆</span>
            </p>
        </div>
      </router-link>
    </div>
    <mt-button class="btn" type="danger" @click="loadmore">加载更多...</mt-button>
  </div>
</template>

<script>
import {Toast} from 'mint-ui'
export default {
  data(){
    return {
      pid:1,
      productList:[],
      totalPage:0,
      productImg:'http://localhost:3000/images/car/'
    }
  },
  methods:{
    initProducts(){
      this.$ajax({
        url:"before/product/"+this.pid,
        method:"get"
      }).then(resp=>{
        this.productList = resp.data.message;
        this.totalPage = resp.data.totalPage;
      })
    },
    loadmore(){
      if(this.pid<this.totalPage){
        this.pid++;
        this.$ajax({
          url:"before/product/"+this.pid,
          method:"get"
        }).then(resp=>{
          this.productList.push(...resp.data.message);
          this.totalPage = resp.data.totalPage;
        })
      }else{
        Toast('亲，没有更多数据了呦！');
      }
    }
  },
  created(){
    this.initProducts();
  }
}
</script>
<style scoped>
.goods-list{
    display: flex;
    flex-wrap: wrap;
    padding:7px;
    justify-content: space-between;
}
.goods-item{
    width:49%;
    border:1px solid #ccc;
    margin:4px 0;
    padding: 2px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 243px;
    border-radius: 6.6px;
    overflow: hidden;
    -webkit-box-shadow: 8px 8px 11px -2px rgba(89,56,67,0.71); 
    box-shadow: 8px 8px 11px -2px rgba(89,56,67,0.71);
}
.goods-list img{
    width: 100%;
}
.title{
    text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
    font-size: 12px;
}
.info{
    background-color: #eee;
}
.info .new{
    color:red;
    font-weight: bold;
    font-size:16px;

}
.info .old{
    text-decoration: line-through;
    margin-left:10px;
    font-size:12px;
}
.sell{
    display: flex;
    justify-content:space-between ;
    font-size:13px;
}
.ys{
  color: #FF5552;
}
.btn{
  width: 100%;
}
</style>